﻿using IdentityModel;
using Microsoft.AspNetCore.Authorization;
using Microsoft.IdentityModel.JsonWebTokens;
using Newtonsoft.Json;
using System.Security.Claims;
using Volo.Abp.Authorization.Permissions;
using Volo.Abp.Users;

namespace AbpVnext_Module.Permission
{
    /// <summary>
    /// 鉴定权限类
    /// </summary>
    public class CustomPermissionValueProvider : PermissionValueProvider
    {
        public IHttpContextAccessor HttpContext { get; set; }


        public CustomPermissionValueProvider(IPermissionStore permissionStore) : base(permissionStore)
        {

        }

        /// <summary>
        /// 基于用户名鉴权
        /// </summary>
        public override string Name => "username";

        /// <summary>
        /// 实现鉴权
        /// </summary>
        /// <param name="context"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public override async Task<PermissionGrantResult> CheckAsync(PermissionValueCheckContext context)
        {
            #region 持久化鉴权
            {
                //throw new NotImplementedException();
                if (HttpContext.HttpContext.User.Identity?.IsAuthenticated == false)
                    return PermissionGrantResult.Undefined;
                //获取Cookie中的用户

                //鉴权失败
                return PermissionGrantResult.Undefined;
            }
            #endregion
        }

        public override Task<MultiplePermissionGrantResult> CheckAsync(PermissionValuesCheckContext context)
        {
            throw new NotImplementedException();
        }
    }
}
